package vue.components;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ListRenderer extends JLabel implements ListCellRenderer  {

	private static final long serialVersionUID = 1L;

	public ListRenderer() {
		setOpaque(false);
	}

	@Override
	public Component getListCellRendererComponent(JList list,
			Object value, // value to display
			int index,    // cell index
			boolean iss,  // is selected
			boolean chf)  // cell has focus?
	{
		setText(((ListItem)value).value);
		setForeground(((ListItem)value).color);

		// Set a border if the list 
		//item is selected 
		if (iss) {
			setBorder(
					BorderFactory.createLineBorder(
							Color.blue, 1));
		} else {
			setBorder(
					BorderFactory.createLineBorder(
							list.getBackground(), 1));
		}
		return this;
	}
}
